﻿<?php


class UserconApp extends BaseApp
{

    var $type = 'usercon';
    var $table_id = 0;	
	var $view_scup_dir = '';

	function __construct() 
	{
      $this->ContentApp();
	}
		
	function ContentApp() 
	{
	   $this->view_scup_dir = ROOT_PATH.'/scup/view/'.VIEW_TYPE;      
	   parent::__construct();
	}	
	
    function index()
    {

        if(!isset($_GET['v']))
		{
		$_GET['v'] = '';
		}
        if(!isset($_GET['tid']))
		{
		$_GET['tid'] = '';
		}		
        $this->table_id	= intval($_GET['tid']);	 
        $order = '';
		$v = $_GET['v'];
		if($v == 'timeasc')
		{
        $order = 'add_time asc';
		}
		else if($v == 'timedesc')
		{
        $order = 'add_time desc';		
		}
		else if($v == 'showyes')
		{
        $order = 'is_show desc';		
		}
		else if($v == 'showno')
		{
        $order = 'is_show asc';		
		}
		else if($v == 'topyes')
		{
        $order = 'is_top desc';		
		}
		else if($v == 'topno')
		{
        $order = 'is_top asc';		
		}
		else if($v == 'recyes')
		{
        $order = 'is_recommend desc';		
		}
		else if($v == 'recno')
		{
        $order = 'is_recommend asc';		
		}
		else if($v == 'indexyes')
		{
        $order = 'is_index desc';		
		}
		else if($v == 'indexno')
		{
        $order = 'is_index asc';		
		}
        $usertype_list_data =  get_usertype_list_data();

        $this->assign('modulename', $usertype_list_data[$this->table_id]['name']);	

		$TB_new = &$this->_model('usercontent');
				
		$data = $TB_new->show($order,$v,$this->table_id,$this->type);	

        $this->assign('lw_data', $data['data']);		
		$this->assign('lw_page', $data['page']);	
									
        $this->assign('appname', $this->type);
        $this->assign('tid', $this->table_id);	
				    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display("usertype_{$this->table_id}_list.view.html");
    }

    function add()
    {
        if(!isset($_GET['tid']))
		{
		$_GET['tid'] = '';
		}		
        $this->table_id	= intval($_GET['tid']);	
		 		
        $usertype_list_data =  get_usertype_list_data();

        $this->assign('modulename', $usertype_list_data[$this->table_id]['name']);		
		$TB_new = &$this->_model('usercontent'); 
		 		
		$TB_new->delet_id($this->table_id,$GLOBALS['SCup']->SCup_user_msg['user_id']);	
		$data_id = $TB_new->insert_id($this->table_id,$GLOBALS['SCup']->SCup_user_msg['user_id']);

		$data = array();
		$data['id'] = $data_id;
        $this->assign('data', $data);	
        $this->assign('id', $data_id);
				
        $this->assign('tid', $this->table_id);		
        $this->assign('appname', $this->type);		
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display("usertype_{$this->table_id}_add.view.html");
    }
	
	
    function addpost()
    {


	     $data = $_POST['data'];
		 $id = $_POST['id'];
		 $this->table_id = $_POST['tid'];

		 $TB_content = &$this->_model('usercontent');
		 		 		 		
		 $TB_content->editaction($id,$data,$this->table_id);
		 
		 $notice = &get_message(array('msg'=>"添加成功！",'url'=>'?app=usercon&act=index&tid='.$this->table_id,'title'=>'Notice'));
		 $notice ->display();

    }




    function edit()
    {
        if(!isset($_GET['tid']))
		{
		$_GET['tid'] = '';
		}		
        $this->table_id	= intval($_GET['tid']);	 		
        $usertype_list_data =  get_usertype_list_data();

        $this->assign('modulename', $usertype_list_data[$this->table_id]['name']);			
		$TB_new = &$this->_model('usercontent'); 	
	
		$id= intval($_GET['id']);
		
				
		$data = $TB_new->oneshow($id,$this->table_id);
		

        $this->assign('edit', 'editp');			

        $this->assign('tid', $this->table_id);
        $this->assign('data', $data);
        $this->assign('appname', $this->type);	
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display("usertype_{$this->table_id}_edit.view.html");     

    }

    function editpost()
    {
		 $id= intval($_POST['id']);
		
		 $data = $_POST['data'];
		 
		 $this->table_id = $_POST['tid'];		
		  
 		$TB_content = &$this->_model('usercontent');  
				
		$TB_content->editaction($id,$data,$this->table_id);
		
		 $notice = &get_message(array('msg'=>"修改成功！",'url'=>'?app=usercon&act=index&tid='.$this->table_id,'title'=>'Notice'));
		 $notice ->display();	      

    }
	
	

    function del()
    {  
	   $this->table_id = $_GET['tid'];		
		$id= intval($_GET['id']);	
	
		$TB_new = &$this->_model('usercontent');
		
		$TB_new->del($id,$this->table_id);

					  
		 $notice = &get_message(array('msg'=>"删除成功！",'url'=>'?app=usercon&act=index&tid='.$this->table_id,'title'=>'Notice'));
		 $notice ->display();   
    }	

    function kindeditor()
    {
    $w = intval($_GET['w']);
    include(ROOT_PATH."/data/ewebeditor/ewebeditor.lib.php");	
	$kindeditor = new Ewebeditor(array('imageUploadCgi'=>SITE_URL.'/admin/index.php?app='.$this->type.'&act=kindeditorupfile&w='.$w));
	$kindeditor->show();
	
    }
	
    function kindeditorupfile()
    {
    $w = intval($_GET['w']);
    include(ROOT_PATH."/data/ewebeditor/ewebeditor.lib.php");	
	$kindeditor = new Ewebeditor(array('imageUploadCgi'=>SITE_URL.'/admin/index.php?app='.$this->type.'&act=kindeditorupfile&w='.$w));
	$kindeditor->upfile($this->type.'/'.$w);	
    }
	
	
    function upfile()
    {
	 if(!isset($_POST["action"]))
	 {
	 $_POST["action"]='';
	 }
	 if(!isset($_GET['id']))
	 {
	 $_GET['id']='';
	 }
	 if(!isset($_GET["edit"]))
	 {
	 $_GET["edit"]='';
	 }	 
	 if(!isset($_GET["picurl"]))
	 {
	 $_GET["picurl"]='';
	 }	
	 if(!isset($_GET['jsfun']))
	 {
	 $_GET['jsfun']='';
	 }		 
	 if(!isset($_GET['putid']))
	 {
	 $_GET['putid']='';
	 }		 
	 if(!isset($_GET['uppic']))
	 {
	 $_GET['uppic']='';
	 }	
		$tf = $_GET['tf'];
        if(empty($tf))$tf = $_POST['tf'];	 	 	
		$action = $_POST["action"];		
		$id = intval($_GET['id']);		
		$jsfun = $_GET['jsfun'];
		$uppic = $_GET['putid'];
		if(!empty($_GET['uppic']))
		{
		$uppic = $_GET['uppic'];		
		}	
		$edit = $_GET["edit"];
		$picurl = $_GET["picurl"];

        $this->assign('jsfun', $jsfun);		


        $this->assign('uppic', $uppic);		
	
				

        $this->assign('edit', $edit);		


        $this->assign('picurl', $picurl);

        $this->assign('tf', $tf);
						
		if($action == 'post')
		{
			 if(!isset($_POST['jsfun']))
	 {
	 $_POST['jsfun']='';
	 }	
	 if(!isset($_POST['uppic']))
	 {
	 $_POST['uppic']='';
	 }		 
	 if(!isset($_POST["edit"]))
	 {
	 $_POST["edit"]='';
	 }		 
	 if(!isset($_POST["picurl"]))
	 {
	 $_POST["picurl"]='';
	 }	
	 if(!isset($_POST['id']))
	 {
	 $_POST['id']='';
	 }		 
		       $jsfun = $_POST['jsfun'];
		       $uppic = $_POST['uppic'];		
		       $edit = $_POST["edit"];
		       $picurl = $_POST["picurl"];
		 	   $id || $id = intval($_POST['id']);		
		       $filedname = trim(str_replace(array("UP_"),array(""),$uppic)); 
       
		       include(ROOT_PATH.'/lib/upfile.lib.php');	  
	           $upfile = new Upfile($this->type.'/'.$id); 	  
	           $updata = $upfile->_batch_upfile($this->type);		 
		 		 
		       $newfile = $updata[1]['path'];
	       
			   if($edit=='editp' && $picurl)
			   {

			          $TB_new = &$this->_model('usercontent');			    		 		 		
		              $TB_new->editpicurl($id,array("$filedname"=>$newfile),$this->table_id);
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
		if(!is_dir($pic_dir)&&file_exists($pic_dir))
		{
		    del_file($pic_dir);	
		}				   
			   }

			    if($edit=='edit' && $picurl)
		       {
		              $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
		if(!is_dir($pic_dir)&&file_exists($pic_dir))
		{
		    del_file($pic_dir);	
		}			 
		       }
		
		      $pic_url = SITE_URL . '/' . UPFILE_PATH . '/' .$newfile;

              if($tf=='pic')
			  {
	           echo "<img src='{$pic_url}' id='upsrc' width='100px' height='100px'><br/><A HREF='?app=$this->type&act=upfile&edit=$edit&tf=$tf&picurl=$newfile&id=$id&jsfun=$jsfun&uppic=$uppic'>修改图片</A>";			  
			  }else
			  {
	           echo "<A HREF='?app=$this->type&act=upfile&edit=$edit&tf=$tf&picurl=$newfile&id=$id&jsfun=$jsfun&uppic=$uppic'>修改文件</A>";			  
			  }

	    echo "<script>
				if(self==top){
					window.opener.$jsfun('$newfile','$uppic');
					window.self.close();
				}else{
					window.parent.$jsfun('$newfile','$uppic');
				}
		     </script>";
				
	    exit;		
		
		}

        $this->assign('id', $id);
	    $this->assign('app', $this->type);		    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');		
		
        $this->display('upfile.view.php');
    }




    function pupfile()
    {	
	 if(!isset($_GET["action"]))
	 {
	 $_GET["action"]='';
	 }
	 if(!isset($_POST["action"]))
	 {
	 $_POST["action"]='';
	 }
	 if(!isset($_GET['id']))
	 {
	 $_GET['id']='';
	 }
	        if(!isset($_POST['id']))
	        {
	          $_POST['id']='';
	        }  	
		$action = $_GET["action"];			
		$action || $action = $_POST["action"];
		
		$id = intval($_GET['id']);
		$cid =$id;
		$tf = $_GET['tf'];
        if(empty($tf))$tf = $_POST['tf'];	
						
		if($action == 'post')
		{
		
		 	   $id || $id = intval($_POST['id']);		
               $cid = $id;
		       include(ROOT_PATH.'/lib/upfile.lib.php');	  
	           $upfile = new Upfile($this->type.'/'.$id); 	  
	           $updata = $upfile->_batch_upfile($this->type);		 
		 		 
		       $newfile = $updata[1]['path'];
			   
               unset($data);
		       $data['uid'] = $GLOBALS['SCup']->SCup_user_msg['user_id'];		       
               $data['con_id'] = $id;
               $data['appname'] = $this->type;			   
			   $data['file_url'] = $updata[1]['path'];
			   $data['size'] = $updata[1]['size'];
			   $data['type'] = $updata[1]['type'];
			   			   
			   $TB_new = &$this->_model('upfile');			    		 		 		
		       $TB_new->post($data);
					   	   
	    }
		else if($action == 'del')
		{
			   $id || $id = intval($_POST['id']);   
			   $TB_new = &$this->_model('upfile');
			   
			    $picdata = $TB_new->oneshow($id);
				$picurl = $picdata['file_url'];
                $cid = $picdata['con_id'];
			   			    		 		 		
		       $TB_new->del($id);
					  
		       $pic_dir= ROOT_PATH . '/' . UPFILE_PATH . '/' . $picurl;
		if(!is_dir($pic_dir)&&file_exists($pic_dir))
		{
		    del_file($pic_dir);	
		}			
		
		}			

	    $TB_new = &$this->_model('upfile');

        $this->assign('picdata', $TB_new ->selct($cid,$this->type));		
        $this->assign('tf', $tf);	
        $this->assign('id', $cid);
	    $this->assign('app', $this->type);					    
        $this->assign('view_charset', VIEW_CHARSET);	
        $this->assign('page_title', SITE_TITLE);
        $this->assign('page_description', SITE_DESCRIPTION);
        $this->assign('page_keywords', SITE_KEYWORDS);	
		
        $this->assign('site_url',SITE_URL);
		
        $this->assign('web_view_dir',SITE_URL.'/admin/view/default/');
		
        $this->display('pupfile.view.php');
    }

	
		
}





?>